package spring.webflux.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import spring.webflux.entity.Personnel;
import spring.webflux.service.PersonnelService;

@RestController
@RequiredArgsConstructor
public class PersonnelController {
    private final PersonnelService personnelService;

    @GetMapping("personnel/{id}")
    public Mono<Personnel> getPersonnelById(@PathVariable int id) {
        return personnelService.getPersonnelById(id);
    }

    @GetMapping("personnel")
    public Flux<Personnel> getAllPersonnel() {
        return personnelService.getAllPersonnel();
    }

    @PostMapping("personnel")
    public Mono<Void> insertPersonnel(@RequestBody Personnel personnel) {
        Mono<Personnel> personnelMono = Mono.just(personnel);
        return personnelService.insertPersonnel(personnelMono);
    }
}
